<?php

declare(strict_types=1);

namespace App\Request\Shop;

use App\Request\FormRequest;
use Hyperf\Validation\Rule;

/**
 * Class Shop
 * @author zx
 * @package App\Request\Shop
 */
class Shop extends FormRequest
{
    /**
     * 场景
     * @var array|\string[][]
     */
    protected array $scenes = [
        'save' => [
            'name',
            'app_id',
            'app_secret',
            'payment_notify'
        ],
        'update' => [
            'app_id',
            'app_secret',
            'payment_notify',
            'status'
        ]
    ];

    /**
     * Determine if the user is authorized to make this request.
     */
    public function authorize(): bool
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     */
    public function rules(): array
    {
        return [
            'name' => [
                'required',
                'max:100',
                Rule::unique('shop')->ignore($this->route('id'))
            ],
            'app_id' => [
                'required',
                'max:50',
                'alpha_num',
                Rule::unique('app')->ignore($this->route('id'))
            ],
            'app_secret' => 'required|max:100|alpha_num',
            'payment_notify' => 'url',
            'status' => 'boolean'
        ];
    }
}
